/* DatabaseTest.cpp
 * This is a testing and interface program for a simple database.
 * It states the functions the user can use to create relations,
 * modify existing relations, and query into the relations.
 */

/*#include all the different files from group members when available*/
#include<iostream>
#include<string>
#include<vector>
#include "DatabaseInterfaceHeader.h"

using namespace std;

int main(){
	string userInput;
	//variable to check for exit after calling helper functions
	//0 means no exit and completed successfully, 1 means exit,
	//2 means command didn't work, reason printed by helper function
	int successful = 0;

	cout<<"Welcome to our simple database program.\n\n";
	
	//continuous loop to allow user to do functions until exit called
	do{
		//Print out the functions for the user to see
		cout<<"\nType exit at any time to quit.\n";
		cout<<"There are currently " <<myDatabase.numRelations() <<" relation(s) in the database.\n";
		cout<<"The functions supported by this database are as follows.\n";
		cout<<"Note: Use the characters shown in parentheses to call the functions.\n";
		cout<<"For example, to use the create relation function, type c at the prompt.\n";
		cout<<"Create Relation(c)\tDelete Relation(r)\tInsert Tuple(i)\n";
		cout<<"Modify Tuple(m)\t\tDelete Tuple(d)\t\tQuery(q)\n";
		cout<<"Print Relation(p)\n\n";

		cout<<"What function do you wish to use?: ";
		getline(cin, userInput);
		userInput = deleteFrontWhitespace(userInput);
		char s = userInput[0];
		successful = 0;

		//switch statement to take the different commands
		switch(s){
			case 'c':
				successful = insertNewRelation();
				break;
			case 'r':
				successful = deleteRelation();
				break;
			case 'i':
				successful = insertNewTuple();
				break;
			case 'm':
				successful = updateTuple();
				break;
			case 'd':
				successful = deleteTuple();
				break;
			case 'q':
				successful = query();
				break;
			case 'p':
				successful = print();
				break;
			default:
				break;
		}
		if(successful==1) return 0;
		if(successful==2) cout<<"\nUnsuccessful command.  Please try again.";
	}while(userInput!="exit");

	return 0;
}
